require('../../assets/css/index.less')
require('./my.less')
const dom = require('../../utils/dom')
const https = require('../../utils/https')
const local = require('../../utils/local');
//     // 引入weui
// require('../../lib/weui/weui')
// require('../../lib/weui/weui.css')
// 引入图标
require('../../assets/fonts/iconfont.css')
// 引入swiper
import Swiper, { Pagination, Autoplay } from 'swiper';

require('swiper/swiper-bundle.css');
//配置插件
//当前轮播图需要使用哪些组件
dom.ready(function () {
    // 底部导航
    dom.bMenu('my')
    Swiper.use([Pagination, Autoplay])
    //2.基本插件配置
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        }
    })
    // 获取个人信息

    // function getUserInfo() {
    //     https.get('/api/user/info', function(res) {
    //         //解构赋值
    //         console.log(res);
    //         let {errno,data}=res;
    //         //判定
    //         if(errno==0){
    //             //解构赋值


    //         }
    //     })
    // }
    // getUserInfo()
    // 打卡功能
    function getClock() {
        https.get('/api/user/clockInInfo', function (res) {
            // console.log(res);
            let { errno, data } = res
            if (errno == 0) {
                dom.getEle('#today').innerHTML = data.isClockIn ? '已经打卡' : '今日打卡'
                dom.getEle('#clockTxt').innerHTML = data.clockCount

            }
        })
    }
    getClock()

    // 打卡
    dom.addEvent('#today', function () {
        console.log(111);
        https.post('/api/user/clockIn', {}, function (res) {
            if (res.errno == 0) {
                alert('打卡成功');
                //渲染按钮上的文字
                getClock()
            } else {
                alert('打卡失败')
            }
        })
    })

    // 渲染
    function getUser() {
        https.get('/api/user/info', function (res) {
            console.log(res);
            let { errno, data } = res
            if (errno == 0) {
                dom.getEle('#heahPic').src = 'http://fitness.h5.itsource.cn:3701' + data.imgUrl
                dom.getEle('#uName').innerHTML = data.nickName
                dom.getEle('#sign').innerHTML = data.sign
                local.set('userData', data)
            }
        })
    }
    getUser()

    // 跳转运动数据
    dom.addEvent("#sptBtn",function(){
        location.href = 'sportdata.html';
    })
    // 跳转徽章
    dom.addEvent("#badegBtn",function(){
        location.href = 'myBadegs.html';
    })

    https.get('/api/exercise',function(res){
        console.log(res);
        let {errno,data}=res;
        if(errno==0){
            dom.getEle("#min").innerHTML=data.sum7Duration;
            dom.getEle("#kll").innerHTML=data.sum7Calorie;
        }
    })
    // https.get('/api/exercise/badge',function(res){
    //     console.log(res);
    // })
})
